<template>
  <div>
    <div class="gllb_box dfh_box">
      <header-comm></header-comm>
      <!-- <yhtjym></yhtjym> -->
      <div class="header_sele" style="left: 10%">
        <div class="add_qy"></div>
        <div>
          <span class="check">
            <a-button type="primary" @click="exportexl">导出excel</a-button>
          </span>
          <div class="date_box">
            <span>时间查询：</span>
            <a-range-picker style="width:260px;" @change="dateChange" />
          </div>
          <div class="date_box">
            <span>订货人：</span>
            <div class="sele">
              <a-input placeholder="请输入订货人" v-model="dhr" style="width: 150px" @change="onSearch" />
              <a-icon type="search" class="search" />
            </div>
          </div>
          <div class="date_box">
            <span>订货公司：</span>
            <div class="sele">
              <a-input
                placeholder="请输入订货公司"
                v-model="dhdwmc"
                style="width: 200px"
                @change="onSearch"
              />
              <a-icon type="search" class="search" />
            </div>
          </div>
          <span>查询销售单：</span>
          <div class="sele">
            <a-input
              v-model="serchvalue"
              placeholder="手机号/销售单编号 "
              style="width: 200px"
              @change="onSearch"
            />
            <a-icon type="search" class="search" />
          </div>
        </div>
      </div>
      <div class="bcg">
        <div class="tabs">
          <a-tabs defaultActiveKey="1" @change="callback">
            <a-tab-pane tab="待发货" key="3"></a-tab-pane>
            <a-tab-pane tab="待收货" key="5"></a-tab-pane>
          </a-tabs>
          <div class="ddgl">
            <a-table
              :pagination="pagination"
              :columns="columns"
              :dataSource="tabslist"
              class="components-table-demo-nested"
              @change="getddgl"
              :scroll="{ x: 1950}"
            >
              <a slot="operation" slot-scope="text,record,index" href="javascript:;">
                <!--  :disabled="record.SHBJB=='交易关闭'||record.SHBJB=='交易完成'?true:false" -->
                <a class="del" @click="ddcl(record)">销售单处理</a>
                <a class="del" @click="kpxx(record.dhrPHONE)">开票信息</a>
                <a class="del" @click="shdz(record.dhrPHONE)">收货地址</a>
                <!-- <a
                  class="del"
                  @click="tjdd(record,index)"
                  v-if="record.ly!='云现货'"
                  :disabled="record.SHBJB=='交易关闭'||record.SHBJB=='交易完成'?true:false"
                >添加</a>-->
              </a>
              <template slot-scope="text, record, index" slot="expandedRowRender">
                <div class="div">
                  <!-- <div class="addchild"><a-button  type="primary" size="small">添加</a-button></div> -->
                  <div class="ddxxlist ddxxhead">
                    <span class="listspan">型号</span>
                    <span class="listspan">品牌</span>
                    <span class="listspan">产地</span>
                    <span class="listspan">库房</span>
                    <!-- <span class="listspan">价格</span> -->
                    <span class="listspan">数量</span>
                    <!-- <span class="listspan">合计</span> -->
                    <!-- <span class="listspan">操作</span> -->
                  </div>
                  <div class="ddxxlist dxbody" v-for="(item,i) in text.child" :key="i">
                    <span class="listspan" :class="'xhval_'+i">{{item.XL}}</span>
                    <span class="listspan" :class="'ppval_'+i">{{item.SCCJC}}</span>
                    <span class="listspan">{{item.sccd}}</span>
                    <span class="listspan">{{item.kfmc}}</span>
                    <span class="listspan">{{item.DHSL}}</span>
                  </div>
                </div>
              </template>
              <template slot-scope="text, record, index" slot="SHBJB">
                <div>
                  <a-tag color="#d6d011" v-if="text=='待发货'">{{text}}</a-tag>
                  <a-tag color="#d6d011" v-if="text=='已发货'">{{text}}</a-tag>
                </div>
              </template>
              <template slot-scope="text, record, index" slot="YUNSHUDH">
                <div>
                  <a @click="getysdh(text,index,record)">{{text}}</a>
                </div>
              </template>
            </a-table>
            <div class="gl_tjwz kpxx_tk" v-if="$store.state.kpxx">
              <kpxx class="gl_tjym"></kpxx>
            </div>
            <div class="gl_tjwz kpxx_tk" v-if="$store.state.shdz">
              <shdz class="gl_tjym"></shdz>
            </div>
            <div class="gl_tjwz kpxx_tk" v-if="ddclflag">
              <ddcltk></ddcltk>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import headerComm from "../header-comm/header.vue";
import ddcltk from "../ddgl/ddcltk.vue";
import kpxx from "../kpxx/kpxx.vue";
import shdz from "../shdz/shdz.vue";

import qs from "qs";
// import { setTimeout, setInterval } from "timers";

// import yhtjym from "../yhtjym/yhtjym.vue";
const columns = [
  {
    title: "操作",
    dataIndex: "operation",
    scopedSlots: { customRender: "operation" }
  },
  { title: "销售单编号", dataIndex: "SQDHDH", key: "SQDHDH" },
  { title: "公司名称", dataIndex: "dhdwmc", key: "dhdwmc" },
  { title: " 订货人", dataIndex: "DHR", key: "DHR" },
  { title: "总数量", dataIndex: "DHSL", key: "DHSL" },
  //   { title: "总金额", dataIndex: "zje", key: "zje" },
  { title: "订购日期", dataIndex: "ZDRQ", key: "ZDRQ" },
  {
    title: "订单状态",
    dataIndex: "SHBJB",
    key: "SHBJB",
    scopedSlots: { customRender: "SHBJB" }
  },
  { title: "收款日期", dataIndex: "fkrq", key: "fkrq" },
  //   { title: "收款方式", dataIndex: "SKFS", key: "SKFS" },
  //   { title: "收款金额", dataIndex: "FPSL", key: "FPSL" },
  { title: "来源", dataIndex: "ly", key: "ly" },
  { title: "运输方式", dataIndex: "YUNSHUFS", key: "YUNSHUFS" },
  {
    title: "运单号",
    dataIndex: "YUNSHUDH",
    key: "YUNSHUDH",
    scopedSlots: { customRender: "YUNSHUDH" }
  },
  { title: "发货日期", dataIndex: "fhrq", key: "fhrq" }
];

const data = [];
const innerColumns = [
  { title: "型号", dataIndex: "XL", key: "XL" },
  { title: "品牌", dataIndex: "SCCJC", key: "SCCJC" },
  { title: "地址", dataIndex: "SZQY", key: "SZQY" }
  //   { title: "价格", dataIndex: "HSJ", key: "HSJ" },
  //   { title: "数量", dataIndex: "DHSL", key: "DHSL" },
  //   { title: "合计", dataIndex: "hj", key: "hj" }
];

const innerData = [];

export default {
  data() {
    return {
      tabskey: 3,

      tabslist: [],
      tabschil: [],
      sele: "",
      serchvalue: "",
      tabslist: [],
      data,
      columns,
      innerColumns,
      innerData,

      ddclflag: false,
      ddclval: [],

      kpxxphone: "",
      page: 0,
      pagination: {
        defaultPageSize: 10,
        showTotal: total => `共 ${total} 条数据`,
        total: 0,
        current: 1
      },
      serchvalue: "",
      dhr: "",
      dhdwmc: "",
      startTime: "",
      endTime: "",
      dfhymflag: false
    };
  },

  methods: {
    //获取列表
    getddgl(pagination, value, key, dhr, dhdwmc, startTime, endTime) {
      this.pagination.current = pagination.current;
      this.axios
        .post(
          "order/orderList.php",
          qs.stringify({
            sqdwid: this.$store.state.bbl_sqdwid,
            shbjb: this.tabskey,
            filed: this.serchvalue,
            page: this.pagination.current,
            pageSize: pagination.defaultPageSize,

            startTime: this.startTime,
            endTime: this.endTime,
            dhr: this.dhr,
            dhdwmc: this.dhdwmc
          })
        )
        .then(res => {
          console.log(res);
          if (res.data.code == 303) {
            this.tabslist = res.data.result;
            this.pagination.total = Number(res.data.totalNum);

            for (var i = 0; i < res.data.result.length; i++) {
              this.tabslist[i].key = i;
              this.tabschil = this.tabslist[i].child;

              for (var j = 0; j < this.tabslist[i].child.length; j++) {
                this.tabslist[i].child[j].key = i + "_" + j;
              }
            }
            // this.nulldata = "";
          } else {
            this.tabslist = [];
            // this.nulldata = "无数据...";
          }
        });
    },
     //导出excel
    exportexl() {
      this.axios
        .post(
          "order/pushOrderLists.php",
          qs.stringify({
            sqdwid: this.$store.state.bbl_sqdwid,
            sqdhdh :this.serchvalue,
            startTime: this.startTime,
            endTime: this.endTime,
            dhr: this.dhr,
            dhdwmc: this.dhdwmc,
            shbjb: this.tabskey

          })
        )
        .then(res => {
          console.log(res);
            if (res.data.code == 303) {
            location.href = res.data.result;

            this.$notification["success"]({
              message: "成功",
              description: res.data.msg,
              duration: 1.5
            });
          } else {
            this.$notification["error"]({
              message: "失败",
              description: res.data.msg,
              duration: 1.5
            });
          }
        });
    },
    //搜索框
    onSearch(e) {
      // this.serchvalue = e.target.value;
      this.page = 1;
      this.getddgl(
        this.pagination,
        this.serchvalue,
        this.tabskey,
        this.dhr,
        this.dhdwmc,
        this.startTime,
        this.endTime
      );
    },
    callback(key) {
      this.tabskey = key;
      console.log(key)
      this.pagination.current = 1;
      // this.page=1
      this.getddgl(this.pagination, this.serchvalue, this.tabskey);
      // this.getddgl(this.pagination, this.serchvalue, this.tabskey,this.dhr,this.dhdwmc,this.startTime,this.endTime);
    },
    dateChange(date, dateString) {
      console.log(date, dateString);
      this.startTime = dateString[0];
      this.endTime = dateString[1];
      this.getddgl(
        this.pagination,
        this.serchvalue,
        this.tabskey,
        this.dhr,
        this.dhdwmc,
        this.startTime,
        this.endTime
      );

      // this.getddgl(this.pagination,this.serchvalue, this.tabskey);
    },
    ddcl(value) {
      this.ddclval = value;
      //   this.dfhymflag = false;
      console.log(value);
      this.ddclflag = true;
    },
    //开票信息
    kpxx(value) {
      console.log(value);
      this.kpxxphone = value;
      this.$store.state.kpxx = true;
    },
    //收货地址
    shdz(value) {
      console.log(value);
      this.kpxxphone = value;
      this.$store.state.shdz = true;
    }
  },

  components: {
    headerComm,
    ddcltk,
    kpxx,
    shdz
  },
  created() {
    this.getddgl(this.pagination, this.serchvalue, this.tabskey);
  }
};
</script>

<style lang='less'>
.dfh_box {
  .header_sele {
    position: absolute;
    top: 55px;
    // left: 200px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 999;
    text-align: right;
    width: 90%;
    background-color: #fff;
    box-shadow: 5px 5px 5px #ccc;
    // height: 50px;
    padding: 10px 20px;
    .check {
      margin-right: 20px;
    }
    .sele {
      position: relative;
      display: inline-block;
      i {
        position: absolute;
        top: 10px;
        right: 8px;
      }
    }
    // .add_qy {
    //   width: auto;
    //   text-align: right;
    //   padding: 10px 0;
    //   display: inline-block;
    //   height: 100%;
    //   button {
    //     margin: 0 10px;
    //   }
    // }
    .date_box {
      display: inline-block;
      margin: 0 10px;
    }
  }
  .tabs {
    position: relative;
    top: 118px;
    background-color: #fff;
    .ant-tabs-bar {
      margin: 0 !important;

      .ant-tabs-nav-wrap {
        text-align: left;
        padding: 15px 40px 0;
      }
    }
  }
}
.ddgl {
  width: 98%;
  position: relative;
  top: 10px;
  left: 1%;
  background-color: #fff !important;
  height: auto;
  padding: 20px;
  th,
  td {
    font-size: 13px;
  }
  .ysdh {
    position: fixed;
    width: 100%;
    height: 1000px;
    z-index: 999;
    top: 0;
    left: 0;
    background: rgba(0, 0, 0, 0.5);
    .ysdh_box {
      width: 700px;
      height: 500px;
      background: #fff;
      /*position: absolute;
    top: 21%;
    left: 32%;*/
      position: relative;
      margin: 0 auto;
      top: 10%;
      overflow: auto;
      .close {
        position: absolute;
        right: 0;
      }
    }
  }

  .gl_tjwz {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    height: 930px;
    .gl_tjym {
      position: absolute;
      width: 80%;
      left: 50%;
      transform: translateX(-50%);
      background-color: #fff;
    }
  }
  .ant-table-body {
    background: #fff;
  }
  .ant-table-wrapper {
    margin: 0 !important;
  }

  .ddxxhead {
    border-bottom: 1px solid #ccc;
    .listspan {
      // color: #bababa;
    }
  }
  .ddxxlist {
    display: flex;
    justify-content: space-between;
    width: 70%;
    padding: 10px;
    .listspan {
      // display: flex;
      // justify-content: space-between;
      width: 20%;
      .anticon svg {
        font-size: 18px;
      }
    }
    .rightspan {
      width: 10%;
      text-align: right;
    }
    span {
      button {
        margin: 0 10px;
      }
      .button {
        background-color: #1890ff;
        border: 0 !important;
      }
    }
    .orange {
      color: red;
      .input {
        outline: none;
        border: 0;
        border: 1px solid #ccc;
        border-radius: 5px;
        padding: 3px 8px;
      }
    }
    .red {
      font-size: 14px;
    }
  }

  ul {
    margin: 0 auto;
    height: auto;
    li {
      margin: 10px 0;
      // border-bottom: 1px solid #ccc;
      background: #fff;
      .colosedd {
        color: #fff;
        background-color: #999 !important;
        border: 0 !important;
      }

      .size {
        font-size: 14px;
        font-weight: bold;
        color: #666;
      }
      .ddxx {
        display: flex;
        justify-content: space-between;
        padding: 10px;
        background-color: #c5c790;
        color: #fff;
        // border-bottom: 1px solid #ccc;

        span {
          margin-right: 20px;
          color: #fff;
        }
      }

      .dxbody {
        //  border-bottom:1px solid #e9e6e6;
      }

      .ddxxfot {
        text-align: left;
        background-color: #f1f1f1;
        padding: 5px 10px;
        position: relative;
        font-size: 14px;
        color: #999;
        top: 42px;
        border-top: 1px solid #ccc;
        span {
          line-height: 25px;
        }
      }
    }
    .fot_tit {
      margin-right: 0px !important;
      color: #000;
    }
  }
  // ul:last-child {
  //   border-bottom: 1px solid #ccc;
  // }
  tbody tr td {
    padding: 10px !important;
  }
}
</style>
